package com.jdj.framework.config.autoconfigure.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author caijinbang
 * @date 2019-04-14 14:19
 */
@ConfigurationProperties(prefix = DubboProperties.PREFIX)
public class DubboProperties {

    public static final String PREFIX = "framework.dubbo";

    private final Annotation annotation = new Annotation();

    private final Application application = new Application();

    private final Protocol protocol = new Protocol();

    private final Provider provider = new Provider();

    private final Consumer consumer = new Consumer();

    private final Registry registry1 = new Registry();

    private final Registry registry2 = new Registry();

    private final Registry registry3 = new Registry();

    private final Monitor monitor = new Monitor();

    private String resolveProperties;

    public Annotation getAnnotation() {
        return annotation;
    }

    public Application getApplication() {
        return application;
    }

    public Protocol getProtocol() {
        return protocol;
    }

    public Provider getProvider() {
        return provider;
    }

    public Consumer getConsumer() {
        return consumer;
    }

    public Registry getRegistry1() {
        return registry1;
    }

    public Registry getRegistry2() {
        return registry2;
    }

    public Registry getRegistry3() {
        return registry3;
    }

    public Monitor getMonitor() {
        return monitor;
    }

    public String getResolveProperties() {
        return resolveProperties;
    }

    public void setResolveProperties(String resolveProperties) {
        this.resolveProperties = resolveProperties;
    }

    /**
     * annotation
     */
    public static class Annotation {

        private String packageName;

        public String getPackageName() {
            return packageName;
        }

        public void setPackageName(String packageName) {
            this.packageName = packageName;
        }

    }

    /**
     * application
     */
    public static class Application {

        private String name = "XxxApplicationName";

        private String logger = "slf4j";

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getLogger() {
            return logger;
        }

        public void setLogger(String logger) {
            this.logger = logger;
        }

    }

    /**
     * protocol
     */
    public static class Protocol {

        /**
         * 接口协议
         */
        private String name = "dubbo";
        /**
         * 暴露服务的端口
         */
        private Integer port = 20880;
        /**
         * 最大请求数据长度
         */
        private Integer payload;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getPort() {
            return port;
        }

        public void setPort(Integer port) {
            this.port = port;
        }

        public Integer getPayload() {
            return payload;
        }

        public void setPayload(Integer payload) {
            this.payload = payload;
        }
    }

    /**
     * provider
     */
    public static class Provider {

        /**
         * 服务的超时时间,单位毫秒
         */
        private Integer timeout;

        /**
         * 调用失败重试次数
         */
        private Integer retries;

        /**
         * 提供者过滤器(文件 com.alibaba.dubbo.rpc.Filter 的配置)
         */
        private String filter = "dubboProviderFilter";

        /**
         * 是否延迟暴露,-1表示不延迟暴露
         */
        private Integer delay;

        public Integer getTimeout() {
            return timeout;
        }

        public void setTimeout(Integer timeout) {
            this.timeout = timeout;
        }

        public Integer getRetries() {
            return retries;
        }

        public void setRetries(Integer retries) {
            this.retries = retries;
        }

        public String getFilter() {
            return filter;
        }

        public void setFilter(String filter) {
            this.filter = filter;
        }

        public Integer getDelay() {
            return delay;
        }

        public void setDelay(Integer delay) {
            this.delay = delay;
        }
    }

    /**
     * consumer
     */
    public static class Consumer {

        /**
         * 服务的超时时间,单位毫秒
         */
        private Integer timeout = 100000;

        /**
         * 消费者过滤器(文件 com.alibaba.dubbo.rpc.Filter 的配置)
         */
        private String filter = "dubboConsumerFilter";

        /**
         * 重复次数
         */
        private Integer retries = 0;

        /**
         * 检查服务提供者是否存在
         */
        private Boolean check = false;

        public Integer getTimeout() {
            return timeout;
        }

        public void setTimeout(Integer timeout) {
            this.timeout = timeout;
        }

        public String getFilter() {
            return filter;
        }

        public void setFilter(String filter) {
            this.filter = filter;
        }

        public Integer getRetries() {
            return retries;
        }

        public void setRetries(Integer retries) {
            this.retries = retries;
        }

        public Boolean getCheck() {
            return check;
        }

        public void setCheck(Boolean check) {
            this.check = check;
        }
    }

    public static class Registry {

        /**
         * id，必须唯一
         */
        private String id;

        /**
         * 接口协议
         */
        private String protocol = "zookeeper";

        /**
         * 是否为缺省
         */
        private Boolean isDefault;

        /**
         * 注册中心地址
         */
        private String address;

        /**
         * 是否向注册中心注册服务
         */
        private Boolean register;

        /**
         * 是否向注册中心订阅服务
         */
        private Boolean subscribe;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getProtocol() {
            return protocol;
        }

        public void setProtocol(String protocol) {
            this.protocol = protocol;
        }

        public Boolean isDefault() {
            return isDefault;
        }

        public void setDefault(Boolean aDefault) {
            isDefault = aDefault;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }


        public Boolean isRegister() {
            return register;
        }

        public void setRegister(Boolean register) {
            this.register = register;
        }

        public Boolean isSubscribe() {
            return subscribe;
        }

        public void setSubscribe(Boolean subscribe) {
            this.subscribe = subscribe;
        }
    }

    /**
     * monitor
     */
    public static class Monitor {

        private String protocol;

        public String getProtocol() {
            return protocol;
        }

        public void setProtocol(String protocol) {
            this.protocol = protocol;
        }
    }
}
